<template>
	<view class="content">
		<view class="title">{{ title }}</view>
		<view class="art-content">
			<rich-text class="richText" :nodes="content"></rich-text>
		</view>
		<button @tap="shareNews" class="share-btn">分享</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			title: '',
			content: ''
		};
	},
	onLoad(e) {
		uni.request({
			url: `https://unidemo.dcloud.net.cn/api/news/36kr/${e.newsid}`,
			method: 'GET',
			success: res => {
				this.title = res.data.title;
				this.content = res.data.content;
			}
		});
	},
	methods: {
		shareNews() {
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneSession',
				title: this.title,
				summary: this.content.slice(0, 50),
				success() {
					uni.showToast({ title: '分享成功', icon: 'success' });
				},
				fail() {
					uni.showToast({ title: '分享失败', icon: 'none' });
				}
			});
		}
	}
}
</script>

<style>
.content { padding: 10px; }
.title { font-size: 24px; font-weight: bold; margin-bottom: 10px; }
.share-btn { color: #fff; background-color: #007aff; padding: 10px; margin-top: 20px; text-align: center; border-radius: 5px; }
</style>
